package controller.admin;
import Message.DTO.DishDTO;
import Message.DTO.DishPageQueryDTO;
import Message.Result;
import Message.vo.DishVO;
import Message.PageResult;
// import io.swagger.annotations.ApiOperation; // 暂时注释，Spring Boot 3.x不兼容
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import service.DishManageService;

import java.util.List;

@Slf4j
@RequestMapping("/admin/dish")
@RestController("adminDishController")
public class DishController {

    @Autowired
    private DishManageService dishManageService;


    @GetMapping("{id}")
    public Result SelectDish(@PathVariable Integer id) {
         DishVO dishVO = dishManageService.SelectDish(id);

      return Result.success(dishVO);

    }
    @GetMapping("/page")
    public Result DishSelectList(DishPageQueryDTO dishPageQueryDTO) {
        log.info("dishPageQueryDTO={}", dishPageQueryDTO);
     PageResult pageResult=  dishManageService.DishSelectList(dishPageQueryDTO);
        return Result.success(pageResult);


    }

    @GetMapping("/list")
    public Result DishCategoryId(@RequestParam Long categoryId, @RequestParam(required = false) String name) {

        log.info("categoryId={}", categoryId);
      List<DishVO> dishVO =dishManageService.DishCategoryId(categoryId,name);

        return Result.success(dishVO);

    }
    @PostMapping("/status/{status}")
public Result StatusDish(@PathVariable Integer status ,Long id){

log.info("status={}",status);
log.info("id={}",id);
        dishManageService.StatusDish(status,id);



return Result.success();

}

     @PutMapping("")
    public Result UpdateDish(@RequestBody DishDTO dishDTO){
          log.info("dishPageQueryDTO={}", dishDTO);

      dishManageService.UpdateDish(dishDTO);

        return Result.success();

     }
     @Transactional
     @PostMapping()
    public Result InsertDish(@RequestBody DishDTO dishDTO){

        log.info("dishPageQueryDTO={}", dishDTO);
        dishManageService.InsertDish(dishDTO);
        return Result.success();

     }

    /**
     * 删除菜品
     * @param ids
     * @return
     */
    // @ApiOperation("删除菜品") // 暂时注释，Spring Boot 3.x不兼容
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("删除菜品：{}", ids);
        dishManageService.delete(ids);

        return Result.success();
    }







}











